/**
 * Copyright (C) 2011, mordredd666 [_at_] gmail.com
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package de.mordred.gui.pruefung;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import de.mordred.Frage;
import de.mordred.Main;
import de.mordred.gui.FixedPanel;
import de.mordred.gui.TopLeiste;
import de.mordred.gui.VerticalFlowLayout;
import de.mordred.gui.lernen.LernenFrageGui;

public class Auswertung extends FixedPanel
{

	private static final long serialVersionUID = 8760172469104369712L;

	public Auswertung(int richtig, int falsch, ArrayList<Frage> fragen)
	{

		int gesamt = richtig + falsch;

		DecimalFormat f = new DecimalFormat("#0.00");
		double prozent = richtig * 100.0 / gesamt;

		this.setLayout(new BorderLayout());

		this.add(new TopLeiste("Auswertung"), BorderLayout.NORTH);

		JButton lernmodus = new JButton("Fragen im Lernmodus");
		lernmodus.setToolTipText("Wechselt mit den aktuellen Fragen in den Lernmodus");

		JPanel center = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE));

		this.add(center, BorderLayout.CENTER);

		center.add(new JLabel("Richtige Antworten:" + richtig));
		center.add(new JLabel("Falsche Antworten:" + falsch));

		center.add(new JLabel(f.format(prozent) + "% richtig"));
		center.add(new JLabel(
				"<html><br>2006 reichten 54% für die Note 4<br>66% - Note 3<br>77% - Note 2<br>89% - Note 1<br><br><u>Die echte Bestehensgrenze hängt von dem Durchschnitt deines Jahrganges ab!</u></html>"));

		this.add(lernmodus, BorderLayout.SOUTH);

		lernmodus.addActionListener(switchLernModus(fragen));
	}

	private ActionListener switchLernModus(final ArrayList<Frage> fragen)
	{
		return new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent e)
			{
				Main.setNextPanel(new LernenFrageGui(fragen, false));
			}
		};
	}
}
